<?php
namespace App\Model\Backstage;
use App\Model\Base;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
/**
 * Class Company
 * @package App\Model\Backstage
 *员工房源业绩统计
 * author:lxy
 * date:2018-6-09
 */
class Achievement extends Base
{
    //定义数据表名
    protected $table = 'achievement';

    public function getAchievementList($map = [],$pageLimit){
        $user_map['u_status'] = 1;
        $user_map['u_b_id']   = $this->branch_id;
        $user_map['u_del'] = 0;
//        return DB::table('user')
//            ->leftjoin($this->table, 'u_id', '=', 'u_id')
//            ->where($map)
//            ->select(DB::raw('sum(a_money) as money'),'u_username','u_account_number','a_uid')
//            ->groupBy('u_id')
//            ->orderBy('money', 'desc')
//            ->paginate($pageLimit);
        $user_list = DB::table('user')
            ->where($user_map)
            ->select(['u_id','u_b_id','u_d_id','u_username','u_type'])
            ->get()
            ->toArray();
        foreach($user_list as $k => $v){
            $map['a_uid'] = $v->u_id;
            $money_num = Achievement::where($map)->sum('a_money');
            $v->money_num= $money_num;
        }
        $list = json_encode($user_list);
        $list = json_decode($list,true);
        array_multisort(array_column($list,'money_num'),SORT_DESC,$list);
        return $list;
    }




}